
package cn.newstrength.lishuai.step;

import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.newstrength.lishuai.data.LSSampleObj;
import cn.newstrength.lishuai.service.LSSampleService;
import cn.newstrength.wtdf.plugin.param.TranParams;
import cn.newstrength.wtdf.plugin.result.TranResult;
import cn.newstrength.wtdf.plugin.util.StepUtils;
import cn.newstrength.wtdf.web.databus.DataContext;
import cn.newstrength.wtdf.web.processor.Operation;
import cn.newstrength.wtdf.web.processor.OperationStep;

/**
 * 事务类型的数据库操作演示
 * @author Xd
 *
 */
public class LSInsertSampleByTransactionalStep2 implements OperationStep {

	private static final Logger logger = LoggerFactory.getLogger(LSInsertSampleByTransactionalStep2.class);

	@Override
	public int excute(Operation oper) {
		/*
		 * 数据总线
		 */
		DataContext ctx = oper.getContext();
		/*
		 * 装载参数
		 */
		LSSampleObj sampleObj = StepUtils.requestToBean(ctx, LSSampleObj.class);
		//sampleObj.setName(null);//将name属性修改为 null 验证Operation级别的事务
		TranParams<LSSampleObj> params = new TranParams<LSSampleObj>(sampleObj);
		params.setResource(ctx.getResource());//Mybatis mapper 配置
		params.setSummary("数据写入");
		logger.info("参数装载完成");
		/*
		 * 获取服务
		 */
		LSSampleService sampleService = oper.getBean("sampleService", LSSampleService.class);
		TranResult<Integer> tranResult = sampleService.insert(params);
		/*
		 * 将结果放置到数据总线上，供其他服务调用
		 */
		ctx.setTranResult(tranResult);
		return 0;
	}

	@Override
	public int init(Map<String, String> input) {
		return 0;
	}

}
